package com.chengyu.core.controller.callback.logic;

import cn.hutool.core.collection.CollectionUtil;
import com.chengyu.core.controller.callback.manager.CallbackFactory;
import com.chengyu.core.exception.ServiceException;
import com.chengyu.core.model.OmsOrder;
import com.chengyu.core.model.OmsOrderRefund;
import com.chengyu.core.service.order.OrderRefundService;
import com.chengyu.core.service.order.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



@Slf4j
@Service("refundLogic")
public class RefundLogic extends CallbackFactory {

	@Autowired
	private OrderRefundService orderRefundService;


	@Autowired
	private OrderService orderService;


	@Override
	public void paySus(String orderNo) {
		throw new UnsupportedOperationException();
	}

	@Override
	public void refundSus(String orderNo) {


		System.out.println("orderNo:"+orderNo);



		OmsOrder order = orderService.getOrderByPayOrderNo(orderNo);
//		OmsOrderRefund refund = orderRefundService.getOrderRefundByRefundNo(order.getId());
		OmsOrderRefund refund = orderRefundService.getOrderRefundByOrderId(order.getId());

		log.info("refund>>"+refund);


		if(CollectionUtil.contains(CollectionUtil.newArrayList(0,1,2,3,4),refund.getStatus())){
			orderRefundService.refundSusCallback(refund);
		}
	}

}
